package cn.gok.plusdemo.controller;


import cn.gok.plusdemo.entity.Clazz;
import cn.gok.plusdemo.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 林
 * @since 2022-07-22
 */
@RestController
@RequestMapping("/clazz")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    //查询所有班级信息
    @RequestMapping("/findAll")
    public List<Clazz> findAllClazz() {
        return clazzService.list(null);
    }

    //根据ID查询班级信息
    @RequestMapping("/findClazzById")
    public Clazz findClazzById(@RequestParam Long id) {
        return clazzService.getById(id);
    }

    //查询所有班级信息和对应的学生信息
    @RequestMapping("findClazzAndStudent")
    public Clazz findClazzAndStudent(@RequestParam long id){
        return clazzService.findClazzAndStudent(id);
    }
    //添加班级
    @RequestMapping("/addClazz")
    public boolean addClazz(@RequestBody Clazz clazz) {
        return clazzService.save(clazz);
    }

    //修改班级信息
    @RequestMapping("/updateClazzById")
    public boolean updateClazzById(@RequestBody Clazz clazz) {
        return clazzService.updateById(clazz);
    }


    //根据id删除班级
    @RequestMapping("/deleById")
    public boolean deleById(@RequestParam Long id) {
        return clazzService.removeById(id);
    }

    //批量删除班级
    @RequestMapping("/deleByIds")
    public boolean deleByIds(@RequestBody List<Integer> ids) {
        return clazzService.removeByIds(ids);
    }
}

